<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:set var="ctx" value="${pageContext.request.contextPath}" /><!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="version" content="Alidao v1.0 20151012">
    <meta http-equiv="Cache-Control" content="must-revalidate,no-cache">
    <meta http-equiv="x-dns-prefetch-control" content="on" />
    <title>心理状态评估</title>
    <link type="text/css" rel="stylesheet" href="${ctx}/static/healthassess/css/common.css" />
    <link rel="stylesheet" href="${ctx}/static/healthassess/css/list.css">
    <link rel="stylesheet" href="${ctx}/static/healthassess/css/health.css">
</head>

<body>
<div class="container health">
    <input type="hidden" value="2" id="questionnaire_id">
    <div class="question-list" id="question_list" style="display:none">
        <h4 class="ps">在过去的两周里, 你生活中<br>以下症状出现的频率有多少？</h4>
    </div>
    <footer class="footer btn-one" style="display:none">
        <a class="bder-radius-4" id="submit" href="javascript:void(0);" onclick="submit()">提交</a>
    </footer>
    <section class="result" id="result" style="display:none">${result}
        <footer class="footer btn-one">
            <a class="bder-radius-4 active"   href="javascript:void(0);" onclick="redo()">重新评估</a>
        </footer>
    </section>
</div>
<script src="${ctx}/static/healthassess/js/jquery-2.1.4.min.js"></script>
<script src="${ctx}/static/healthassess/js/jquery.mobile.custom.min.js"></script>
<script src="${ctx}/static/healthassess/js/common.js"></script>
<script>
    var questionJson = [{
        type: "radio",
        question: "1.做事时提不起劲或没有兴趣",
        answer: {
            answerArray: [
                "没有",
                "有几天", "一半以上时间", "几乎天天", //总计得分
            ]
        },
        next: 2,
    }, {
        type: "radio",
        question: "2.感到心情低落, 沮丧或绝望，",
        answer: {
            answerArray: [
                "没有",
                "有几天", "一半以上时间", "几乎天天", //总计得分
            ]
        },
        next: 3,
    }, {
        type: "radio",
        question: "3.入睡困难、睡不安或睡得过多",
        answer: {
            answerArray: [
                "没有",
                "有几天", "一半以上时间", "几乎天天", //总计得分
            ]
        },
        next: 4,
    }, {
        type: "radio",
        question: "4.感觉疲倦或没有活力",
        answer: {
            answerArray: [
                "没有",
                "有几天", "一半以上时间", "几乎天天", //总计得分
            ]
        },
        next: 5,
    }, {
        type: "radio",
        question: "5.食欲不振或吃太多",
        answer: {
            answerArray: [
                "没有",
                "有几天", "一半以上时间", "几乎天天", //总计得分
            ]
        },
        next: 6,
    }, {
        type: "radio",
        question: "6.觉得自己很糟或觉得自己很失败，或让自己、家人失望",
        answer: {
            answerArray: [
                "没有",
                "有几天", "一半以上时间", "几乎天天", //总计得分
            ]
        },
        next: 7,
    }, {
        type: "radio",
        question: "7.对事物专注有困难，例如看报纸或看电视时",
        answer: {
            answerArray: [
                "没有",
                "有几天", "一半以上时间", "几乎天天", //总计得分
            ]
        },
        next: 8,
    }, {
        type: "radio",
        question: "8.行动或说话速度缓慢到别人已经察觉？或刚好相反——变得比平日更烦躁或坐立不安，动来动去",
        answer: {
            answerArray: [
                "没有",
                "有几天", "一半以上时间", "几乎天天", //总计得分
            ]
        },
        next: 9,
    }, {
        type: "radio",
        question: "9.有不如死掉或用某种方式伤害自己的",
        answer: {
            answerArray: [
                "没有",
                "有几天", "一半以上时间", "几乎天天", //总计得分
            ]
        },
        next: "finish",
    }];
</script>
<script>
    $(function() {
        if (${not empty result}) {
            $("#result").show();
            return;
        }else{
            $("#result").siblings("div,footer").show();
        }
        select_click();
        verify();
    });
    var scoreArray = [];
    var resultHtml;
    var select_click = function() {
        $(".list").each(function(index) {
            $(this).find("li").tap(function() {
                onSelecting($(this));
                getAnswer(index, $(this));
                var score = $(this).index();
                scoreArray[index] = score;
                verify();
            })
        })
    }
    var sum = 0;
    function result_html(){
        resultHtml="";
        for (var i = 0; i < scoreArray.length; i++) {
            sum += scoreArray[i];
        }
        if (sum >= 0 && sum < 5) {
            resultHtml = '<div class="result-list">' +
            '<h4>您的心理很健康!</h4>' +
            '<ul>' +
            '<li><p>请继续保持！</p></li>' +
            '</ul>' +
            '</div>';
        } else if (sum >= 5 && sum <= 9) {
            resultHtml = '<div class="result-list">' +
            '<h4>可能有轻微抑郁症</h4>' +
            '<ul>' +
            '<li><p>建议咨询心理医生或心理医学工作者</p></li>' +
            '</ul>' +
            '</div>';

        } else if (sum >= 10 && sum <= 14) {
            resultHtml = '<div class="result-list">' +
            '<h4>可能有中度抑郁症</h4>' +
            '<ul>' +
            '<li><p>最好咨询心理医生或心理医学工作者</p></li>' +
            '</ul>' +
            '</div>';

        } else if (sum >= 15 && sum <= 19) {
            resultHtml = '<div class="result-list">' +
            '<h4>可能有中重度抑郁症</h4>' +
            '<ul>' +
            '<li><p>建议咨询心理医生或精神科医生</p></li>' +
            '</ul>' +
            '</div>';

        } else if (sum >= 20 && sum <= 27) {
            resultHtml = '<div class="result-list">' +
            '<h4>可能有重度抑郁症　</h4>' +
            '<ul>' +
            '<li><p>一定要看心理医生或精神科医生</p></li>' +
            '</ul>' +
            '</div>';
        }
    }

    function verify(){
        var questionLength=$(".question").length;
        var isDo=$("[data-status='do']");
        if(isDo.length<questionLength){
            $("#submit").removeClass('active').attr("onclick","");
        }else{
            $("#submit").addClass('active').attr("onclick","submit()");
        }
    }

    function submit() {
        getData();
        result_html();
        var result = resultHtml;
        var questionArray = dataArr;
        var questionnaire_id = "2";
        var questionnaire = "心理状态评估";
        var data = {
            uid: ${uid},
            questionnaireId: questionnaire_id,
            questionnaire: questionnaire,
            questionArray: JSON.stringify(questionArray),
            result: result,
            score: sum
        };
        $.ajax({
            url: '${ctx}/h5/health/assessment/save',
            type: 'post',
            data: data,
            success:function(){

            }
        });
        $(window).scrollTop(0);
        $("#result footer").before(resultHtml);
        $("#result").siblings('div,footer').hide();
        $("#result").show();
        $("#tips").hide();
    }
</script>
</body>

</html>
